﻿#region using statements

using Microsoft.Xna.Framework;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameState;

using Nuclex.UserInterface;
using Nuclex.UserInterface.Controls;
using Nuclex.UserInterface.Controls.Desktop;

using TowerDefense.Misc;
using TowerDefense.States;

#endregion

namespace TowerDefense.GUILayouts
{
	public class GUIElementGameOverLayout : GUIElement
	{
		private readonly LabelControl m_label = new LabelControl();

		private readonly ButtonControl m_menuButton = new ButtonControl();

		private readonly ButtonControl m_restartButton = new ButtonControl();

		private readonly LabelControl m_scoreLabel = new LabelControl();

		private readonly ButtonControl m_window = new ButtonControl();

		protected override void _Cleanup() {}

		protected override void _Initialize() {
			m_window.Bounds = new UniRectangle(new UniScalar(0.2f, 0), new UniScalar(0.2f, 0), new UniScalar(0.6f, 0), new UniScalar(0.6f, 0));
			m_window.Enabled = false;

			m_label.Text = "GAME OVER";
			m_label.Bounds = new UniRectangle(new UniScalar(0.4f, 0), new UniScalar(0.3f, 0), 0, 0);
			m_scoreLabel.Text = "Your score: " + GameEngine.GetService<GameStats>().TotalGold;
			m_scoreLabel.Bounds = new UniRectangle(new UniScalar(0.4f, 0), new UniScalar(0.5f, 0), 0, 0);

			m_menuButton.Text = "Return to menu";
			m_menuButton.Bounds = new UniRectangle(new UniScalar(0.3f, -70), new UniScalar(0.8f, 0), 140, 40);
			m_menuButton.Pressed += delegate { GameEngine.GetService<IManagerGameState>().ChangeState(new GameStateMenu(), true); };
			m_restartButton.Text = "Try again";
			m_restartButton.Bounds = new UniRectangle(new UniScalar(0.7f, -70), new UniScalar(0.8f, 0), 140, 40);
			m_restartButton.Pressed += delegate { GameEngine.GetService<IManagerGameState>().ChangeState(new GameStatePlay(), true); };

			m_window.Children.Add(m_label);
			m_window.Children.Add(m_scoreLabel);
			m_window.Children.Add(m_restartButton);
			m_window.Children.Add(m_menuButton);
			_Children.Add(m_window);
		}

		protected override void Update(GameTime p_gameTime) {}
	}
}